package filter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;

import error.GedivaException;

/**
 * The abstract class for the Filter object
 * 
 * @author Trevor
 * 
 */
public abstract class Filter<T, U> implements IFilter<T, U>
{
    private String myResourceName;
    private ResourceBundle myParams = ResourceBundle
            .getBundle("properties/FilterParams");
    // the constraints, such as the bounds on x or y
    private List<String> myConstraints;

    public Filter(String resourceName)
    {
        myResourceName = resourceName;
    }

    /**
     * stores a list of the constraints.
     * 
     * @param constraints
     */
    public void storeParameters(List<String> constraints)
    {
        myConstraints = new ArrayList<String>(constraints);
        if (myConstraints.contains(null))
            throw new GedivaException("You must input a value");
    }

    /**
     * returns the list of constraints
     * 
     * @return constraints
     */
    protected List<String> getStoredConstraints()
    {
        return myConstraints;
    }

    public List<String> getPrompts()
    {
        String[] paramNames = myParams.getString(myResourceName).split(
                "\\s*,\\s*");
        List<String> output = new ArrayList<String>();
        for (String k : paramNames)
        {
            output.add(k);
        }
        return output;
    }

    public abstract String toString();

    public abstract Map<Object, List<Object>> filterData(
            Map<Object, List<Object>> data);

}
